﻿Namespace EIB.Bus.FT12
    Public MustInherit Class FT12_FrameBase
        Inherits FrameBase

        Public Shared FT12_STARTFIXED As Byte = &H10
        Public Shared FT12_STARTVARIABLE As Byte = &H68
        Public Shared FT12_END As Byte = &H16
        Public Shared FT12_ACK As Byte = &HE5
        Public Shared FT12_Reset As Byte() = New Byte() {&H10, &H40, &H40, FT12_END}

        Protected _FT12_Data As Byte() = Nothing
        Protected _type As FT12_FrameType = Nothing


        Sub New(type As FT12_FrameType)
            If Not [Enum].IsDefined(GetType(FT12_FrameType), type) Then Throw New ArgumentException("")

            _type = type
        End Sub

        Sub New(busData As Byte())
            If busData Is Nothing Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If busData.Length < 1 Then Throw New EIB.Exceptions.EIBDataDecodeException("")
            If Not [Enum].IsDefined(GetType(FT12_FrameType), busData(0)) Then Throw New EIB.Exceptions.EIBDataDecodeException("")

            _FT12_Data = busData

            _type = busData(0)
        End Sub


        Public ReadOnly Property BusData As Byte()
            Get
                Return _FT12_Data
            End Get
        End Property

        Public ReadOnly Property Type As FT12_FrameType
            Get
                Return _type
            End Get
        End Property


        Public Shared Function GetFrameType(data As Byte()) As FT12_FrameType
            Return CType(data(0), FT12_FrameType)
        End Function
    End Class
End Namespace